﻿using Abp.Domain.Services;
using shenghua.SMS.ThirdParties.AliSMSes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.SMS
{
    public class SMSManager: DomainService
    {
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <returns></returns>
        public static string GenerateCaptcha()
        {
            int number;
            char code;
            string checkCode = string.Empty;
            Random random = new Random();
            for (int i = 0; i < 6; i++)
            {
                number = random.Next();
                code = (char)('0' + (char)(number % 10));
                checkCode += code.ToString();
            }
            return checkCode;
        }

        /// <summary>
        /// 验证手机号
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public static bool CheckPhoneNumber(string phoneNumber)
        {
            string regex = "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";
            //string regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
            return System.Text.RegularExpressions.Regex.IsMatch(phoneNumber, regex);
        }

        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="captcha"></param>
        public void SendCaptcha(string phoneNumber, string captcha)
        {
            var alisms = new AliSMSManager();
            alisms.SendCaptcha(phoneNumber, captcha);
        }
    }
}
